﻿using B.MES.Customer.Application.IApplication;
using B.MES.Customer.Domain;
using B.MES.Customer.Domain.DTO;
using B.MES.Customer.Infrastructure.IRepository;
using B.MES.Customer.Infrastructure.Repository;
using MySqlX.XDevAPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.MES.Customer.Application.Application
{
    public class ProductApplication : BaseApplication<Product>, IProductApplication
    {
        /// <summary>
        /// 仓储服务注入
        /// </summary>
        private readonly IProductRepository _productRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="produceRepository">仓储服务</param>
        public ProductApplication(IProductRepository productRepository) : base(productRepository)
        {
            _productRepository = productRepository;
        }

        /// <summary>
        /// 绑定产品属性表的下拉框
        /// </summary>
        /// <returns>返回产品属性表数据</returns>
        public List<Matattribute> GetProductShow()
        {
            return _productRepository.GetProductShow();
        }
        /// <summary>
        /// 绑定产品类别表的下拉框
        /// </summary>
        /// <returns>返回产品类别表数据</returns>
        public List<MatTypeinfo> GetProductinfoShow()
        {
            return _productRepository.GetProductinfoShow();
        }
        /// <summary>
        /// 绑定产品单位表的下拉框
        /// </summary>
        /// <returns>返回产品单位表数据</returns>
        public List<MatUnitInfo> GetProductUnitInfoShow() 
        {
            return _productRepository.GetProductUnitInfoShow();
        }
        /// <summary>
        /// 添加产品
        /// </summary>
        /// <param name="productDTO"></param>
        /// <returns></returns>
        public APIResult<ProductDTO> AddProduct(ProductDTO productDTO)
        {
            try
            {
                return _productRepository.AddProduct(productDTO);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 显示产品列表
        /// </summary>
        /// <param name="product_Name">产品名称</param>
        /// <param name="model_Number">规格型号</param>
        /// <param name="brand">品牌</param>
        /// <param name="page">页码</param>
        /// <param name="size">页容量</param>
        /// <returns></returns>
        public PageApiResut<ProductDTO> GetUserListByKeyword(string? product_Name, string? model_Number, string? brand, int page, int size)
        {
            try
            {
                return _productRepository.GetUserListByKeyword(product_Name, model_Number, brand, page, size);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 删除产品信息
        /// </summary>
        /// <param name="product_Id"></param>
        /// <returns></returns>
        public APIResult<Product> DeleteData(int product_Id)
        {
            try
            {
                return _productRepository.DeleteData(product_Id);   
            }
            catch (Exception)
            {

                throw;
            } 
        }

        /// <summary>
        /// 产品反填
        /// </summary>
        /// <param name="product_Id"></param>
        /// <returns></returns>
        public APIResult<ProductListDTO> GetStockInSel(int product_Id)
        {
            try
            {
                return _productRepository.GetStockInSel(product_Id);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 产品修改
        /// </summary>
        /// <param name="productDTO"></param>
        /// <returns></returns>
        public APIResult<ProductDTO> UpdateProductSel(ProductDTO productDTO)
        {
            try
            {
                return _productRepository.UpdateProductSel(productDTO);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
